/* INFLOWS OF IMMIGRANTS PER REGIONS */
/* TABLE 2 PANEL A VERSION FEB 2020 */
/* Sortie */
libname harmo "C:\Users\Public\Documents\donnees\RP_Harmo\"; /* taille longue */
libname hmini "C:\Users\Public\Documents\donnees\RP_Harmo\mini"; /* petite taille */
libname ccom "C:\Users\Public\Documents\donnees\Code_commune";

data rp07;
set harmo.hrp07 (keep = age homme immig nimmig cgeo sond);
dep=substr(cgeo,1,2);
drop age homme cgeo;
an="2007";
run;

data rp99;
set harmo.hrp99 (keep = age homme immig nimmig cgeo sond);
dep=substr(cgeo,1,2);
drop age homme cgeo;
an="1999";
run;

data rp90;
set harmo.hrp90 (keep = age homme immig  nimmig cgeo sond);
dep=substr(cgeo,1,2);
drop age homme cgeo;
an="1990";
run;

data rp82;
set harmo.hrp82 (keep = age homme immig nimmig cgeo sond);
dep=substr(cgeo,1,2);
drop age homme cgeo;
an="1982";
run;

data rp75;
set harmo.hrp75 (keep = age homme immig nimmig cgeo sond);
dep=substr(cgeo,1,2);
drop age homme cgeo;
an="1975";
run;

data rp;
set rp07 rp99 rp90 rp82 rp75;
run;
proc sort data=rp;
by dep;
run;

/* code r�gions */
data creg;
set ccom.france2012 (keep = reg dep);
if dep="20" then reg="94";
run;
proc sort data=creg nodupkeys;
by dep reg;
run;
/* nouvelles r�gions */
data creg;
set creg;
if reg="11" then nreg="11";
if reg="24" then nreg="24";
if reg="26" | reg="43" then nreg="27";
if reg="23" | reg="25" then nreg="28";
if reg="31" | reg="22" then nreg="32";
if reg="42" | reg="21" | reg="41"  then nreg="44";
if reg="52" then nreg="52";
if reg="53" then nreg="53";
if reg="72" | reg="74" | reg="54"  then nreg="75";
if reg="91" | reg="73" then nreg="76";
if reg="83" | reg="82" then nreg="84";
if reg="93" then nreg="93";
if reg="94" then nreg="94";
/* DOM TOM */
if reg="01" then nreg="01";
if reg="02" then nreg="02";
if reg="03" then nreg="03";
if reg="04" then nreg="04";
if reg="06" then nreg="06";
run;
proc freq data=creg;
table nreg;
run;

/* merge rp data with new region data */
proc sort data=rp;
by dep;
run;
proc sort data=creg;
by dep;
run;
data rp;
merge rp (in = x) creg ;
by dep;
if x;
drop reg reg;
run;

/* TABLE 2 PANEL A */
/* SHARE NEW IMMIGRANTS BY REGIONS */
proc sort data=rp;
by nreg;
run;
proc freq data=rp;
by nreg;
weight sond;
table nimmig*an;
run;
